package com.bluean.daily.cloud.service.base.controller;

import com.bluean.daily.cloud.service.system.client.feign.SystemTestFeign;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.redisson.api.RMap;
import org.redisson.api.RedissonClient;
import org.redisson.client.codec.StringCodec;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.BoundHashOperations;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author: blue_an
 * @date: 2023/12/31/18:40
 * @description: TODO
 */
@RestController
@RequestMapping(value = "baseTest")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@Api(tags = "daily-base-test")
public class BaseTestController {

    private final SystemTestFeign systemTestFeign;

    private final RedissonClient redissonClient;

    private final RedisTemplate<String, String> redisTemplate;

    @GetMapping("/test")
    @ApiOperation(value = "base 测试接口")
    public String test() {
        return systemTestFeign.test();
    }

    @ApiOperation(value = "缓存测试设置值")
    @GetMapping(value = "redis/set")
    public String redisSet() {
        RMap<Object, Object> m = redissonClient.getMap("test", StringCodec.INSTANCE);
        m.put("1", "Test");
        return "设置成功";
    }

    @ApiOperation(value = "缓存测试获取值")
    @GetMapping(value = "redis/get")
    public String redisGet() {
        BoundHashOperations<String, String, String> hash = redisTemplate.boundHashOps("test");
        return hash.get("1");
    }

}
